/**
 * UI管理类
 * 主要用于管理对话框的显示与隐藏
 *
 * @export
 * @class UiManager
 */
export class UiManager {
  public static showDialog(node: cc.Node): Promise<Boolean> {
    return new Promise((resolve, reject) => {
      if (!node) reject(false);
      node.active = true;
      // mask淡入
      let mask: cc.Node = node.getChildByName("bg");
      if (mask) {
        mask.opacity = 0;
        cc.tween(mask).to(0.3, { opacity: 100 }, { easing: "fade" }).start();
      }
      // content缩放显示
      let content: cc.Node = node.getChildByName("content");
      content.setScale(0, 0);
      cc.tween(content)
        .to(0.4, { scale: 1 }, { easing: "backOut" })
        .call(() => {
          resolve(true);
        })
        .start();
    });
  }
  public static hideDialog(node: cc.Node): Promise<Boolean> {
    return new Promise((resolve, reject) => {
      if (!node) reject(false);
      // mask淡出
      let mask = node.getChildByName("bg");
      if (mask) {
        cc.tween(mask).to(0.3, { opacity: 0 }, { easing: "fade" }).start();
      }
      // content缩放隐藏
      let content: cc.Node = node.getChildByName("content");
      cc.tween(content)
        .to(0.4, { scale: 0 }, { easing: "backIn" })
        .call(() => {
          node.active = false;
          resolve(true);
        })
        .start();
    });
  }
}
